package com.algrithom.array;

import java.util.ArrayList;
import java.util.List;

/**
 * 118. 杨辉三角
 * 
 * @author think
 */
public class Solution6 {
    
    public static void main(String[] args){
        Solution6 solution6 = new Solution6();
        List<List<Integer>> result = solution6.generate(5);
        for (int i = 0; i < result.size(); i++) {
            System.out.println(result.get(i));
        }
    }
    
    public List<List<Integer>> generate(int numRows){
        List<List<Integer>> result = new ArrayList<>(numRows);
        result.add(new ArrayList<>(1));
        result.get(0).add(1);
        for (int row = 1; row < numRows; row++) {
            List<Integer> list = new ArrayList<>();
            list.add(1);
            for (int col = 0; col + 1 < row; col++) {
                list.add(result.get(row - 1).get(col) + result.get(row - 1).get(col + 1));
            }
            list.add(1);
            result.add(list);
        }
        return result;
    }
}
